package com.ghost.view.Loading
{
	import com.ghost.data_struct.HashMap;
	import com.ghost.interfaces.Iloading;
	import com.ghost.manager.Source_manager;
	import com.ghost.manager.System_set;
	import com.ghost.model.Configure_url;
	import com.ghost.model.Object_pool;
	import com.ghost.view.pop.Pop_base;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	import flashx.textLayout.formats.TextAlign;

	/**
	 * @author ghost
	 * 大的loading
	 */
	public class Loading_big_mc extends Pop_base implements Iloading
	{
		private var des_txt:TextField;//描述性文本
		private var total_txt:TextField;//显示总进度的文本
		
		private var loading_bg_mc:Bitmap;//整个背景
		private var loading_s:Sprite;//loading条的容器
		private var loading_b:Bitmap;//loading条的动态变化部分
		
		private var loading_bg_bd:BitmapData;
		private var loading_left_bd:BitmapData;
		private var loading_center_bd:BitmapData;
		private var loading_right_bd:BitmapData;
		private var loading_bd:BitmapData;
		public function Loading_big_mc()
		{
			this.type=1;
			loading_bg_bd = Source_manager.getInstance().getBitmapData('loading_bg');
			loading_left_bd = Source_manager.getInstance().getBitmapData('loading_left');
			loading_center_bd = Source_manager.getInstance().getBitmapData('loading_center');
			loading_right_bd = Source_manager.getInstance().getBitmapData('loading_right');
			loading_bd = Source_manager.getInstance().getBitmapData('loading');
			var ui_data_h:HashMap = new HashMap();
			ui_data_h.put('loading_bg',loading_bg_bd);
			ui_data_h.put('loading_left',loading_left_bd);
			ui_data_h.put('loading_center',loading_center_bd);
			ui_data_h.put('loading_right',loading_right_bd);
			ui_data_h.put('loading',loading_bd);
			Object_pool.loaded_obj_pool.put("loading_ui",ui_data_h);
			creat_ui();
		}
		private function creat_ui():void
		{
			loading_bg_mc = new Bitmap(loading_bg_bd);
			this.addChild(loading_bg_mc);
			loading_s = new Sprite();
			this.addChild(loading_s);
			var loading_left_mc:Bitmap = new Bitmap(loading_left_bd);
			var loading_center_mc:Bitmap = new Bitmap(loading_center_bd);
			var loading_right_mc:Bitmap = new Bitmap(loading_right_bd);
			loading_b = new Bitmap(loading_bd);
			loading_s.addChild(loading_left_mc);
			loading_s.addChild(loading_center_mc);
			loading_center_mc.x=loading_left_mc.width;
			loading_center_mc.width = 200;
			loading_s.addChild(loading_right_mc);
			loading_right_mc.x = loading_center_mc.x+loading_center_mc.width;
			loading_s.addChild(loading_b);
			loading_b.x=loading_left_mc.width;
			loading_b.y=3;
			
			des_txt = new TextField();
			des_txt.width = 60;
			des_txt.height = 20;
			this.addChild(des_txt);
			total_txt = new TextField();
			total_txt.width = 60;
			total_txt.height = 20;
			this.addChild(total_txt);
			des_txt.autoSize = TextAlign.CENTER;
			total_txt.autoSize = TextAlign.CENTER;
			des_txt.selectable = false;
			total_txt.selectable = false;
			total_txt.x = (this.width-total_txt.width)/2;
			total_txt.y = this.height-total_txt.height-2;
			des_txt.x = (this.width-des_txt.width)/2;
			des_txt.y = total_txt.y-des_txt.height-2;
			loading_s.x = (this.width-loading_s.width)/2;
			loading_s.y = des_txt.y-loading_s.height-5;
		}
		/**
		 *data_str:显示总进度 ...arg:其他额外加的
		 */		
		public function show_total(data_str:String):void
		{
			total_txt.text = data_str;
		}
		/**
		 *控制动画 
		 */	
		public function show_change(des_str:String,num:int):void
		{
			if(des_txt)des_txt.text = des_str+"加载中..."+String(num)+"%";
			//动画控制
			if(loading_b)loading_b.width=num*2;
		}
	}
}